package com.bailan.controller;

import com.bailan.pojo.Admin;
import com.bailan.pojo.Student;
import com.bailan.pojo.Teacher;
import com.bailan.service.IAdminService;
import com.bailan.service.IStudentService;
import com.bailan.service.ITeacherService;
import com.bailan.utils.CheckUser;
import com.baomidou.mybatisplus.extension.service.IService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author BaiLan
 * @since 2022:05:24
 */
@RestController
@RequestMapping("/login")
public class LoginController {


    private IAdminService adminService;

    private IStudentService studentService;

    private ITeacherService teacherService;


    @Autowired
    public void setAdminService(IAdminService adminService) {
        this.adminService = adminService;
    }

    @Autowired
    public void setStudentService(IStudentService studentService) {
        this.studentService = studentService;
    }

    @Autowired
    public void setTeacherService(ITeacherService teacherService) {
        this.teacherService = teacherService;
    }

    /**
     * 管理员登录接口
     *
     * @param user 用户
     * @return 管理员信息
     */
    @RequestMapping(value = "/admin", method = RequestMethod.GET, consumes = "application/json")
    public String checkLoginAdminData(@RequestBody Admin user) {


        Admin check = CheckUser.check(adminService, user);

        return check != null ? check.toString() : null;

    }


    /**
     * 学生登录接口
     *
     * @param user 用户
     * @return 学生信息
     */

    @RequestMapping(value = "/student", method = RequestMethod.GET, consumes = "application/json")
    @ResponseBody
    public String checkLoginStudentData(@RequestBody Student user) {

        Student check = CheckUser.check(studentService, user);


        return check != null ? check.toString() : null;

    }


    /**
     * 教师登录接口
     *
     * @param user 用户
     * @return 学生信息
     */
    @RequestMapping(value = "/teacher", method = RequestMethod.GET, consumes = "application/json")
    @ResponseBody
    public String checkLoginTeacherData(@RequestBody Teacher user) {

        Teacher check = CheckUser.check(teacherService, user);

        return check != null ? check.toString() : null;

    }




}
